package T5;

public class MatrixTest {
    public static void main(String[] args) {
        try {
            // 正常情况下的矩阵创建和乘法运算
            double[][] a1 = {{1, 2}, {2, 3}};
            Matrix mat1 = new Matrix(a1);
            double[][] a2 = {{1, 3}, {2, 3}};
            Matrix mat2 = new Matrix(a2);
            Matrix multiply = mat1.mulitiply(mat2);
            multiply.print();

            // 尝试创建一个非法的矩阵（比如，使用负的行数或列数）
            System.out.println("尝试创建一个非法的矩阵：");
            Matrix invalidMatrix = new Matrix(-1, 3);
        } catch (MIllegalArgumentException e) {
            System.out.println("捕获到异常: " + e.getMessage());
        }

        try {
            // 尝试执行不可行的矩阵乘法
            System.out.println("尝试进行不可行的矩阵乘法：");
            double[][] b1 = {{1, 2, 3}};
            Matrix mat3 = new Matrix(b1);
            double[][] b2 = {{1, 2}, {3, 4}};
            Matrix mat4 = new Matrix(b2);
            Matrix result = mat3.mulitiply(mat4); // 这里可能抛出异常
        } catch (MatrixMultiplicationException e) {
            System.out.println("捕获到异常: " + e.getMessage());
        } catch (MIllegalArgumentException e) {
            throw new RuntimeException(e);
        }
    }
}
